/*!
\copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.\n
            All Rights Reserved.\n
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file       le_audio_bap_profile_channel_event_spec.h
\brief      Events sent by the LE Audio BAP profile
*/

#ifndef LE_AUDIO_PROFILE_CHANNEL_EVENT_SPEC_H_
#define LE_AUDIO_PROFILE_CHANNEL_EVENT_SPEC_H_

#include "channel_event_spec_ids.h"
#include "gatt_uuids.h"
#include "volume_types.h"


/*! @{ */

/*! \brief The LE Audio BAP profile event channel */
#define EVENT_BUS_CHANNEL_LE_AUDIO_BAP_PROFILE          le_audio_bap_profile_event_channel
#define EVENT_BUS_CHANNEL_LE_AUDIO_MCP_PROFILE          le_audio_mcp_profile_event_channel
#define EVENT_BUS_CHANNEL_LE_AUDIO_CCP_PROFILE          le_audio_ccp_profile_event_channel
#define EVENT_BUS_CHANNEL_LE_AUDIO_MICP_PROFILE         le_audio_micp_profile_event_channel
#define EVENT_BUS_CHANNEL_LE_AUDIO_VCP_PROFILE          le_audio_vcp_profile_event_channel
#define EVENT_BUS_CHANNEL_LE_AUDIO_CSIP_PROFILE         le_audio_csip_profile_event_channel

/*! \brief The LE Audio profile events that are sent. */
typedef enum
{
    le_audio_profile_event_gatt_read_ind,                   /*!< \ref le_audio_profile_event_gatt_common_data_t for event data */
    le_audio_profile_event_gatt_read_response_ind,          /*!< \ref le_audio_profile_event_gatt_common_data_t for event data */
    le_audio_profile_event_gatt_write_ind,                  /*!< \ref le_audio_profile_event_gatt_common_data_t for event data */
    le_audio_profile_event_gatt_write_response_ind,         /*!< \ref le_audio_profile_event_gatt_common_data_t for event data */
    le_audio_profile_event_gatt_write_response_more_ind,    /*!< \ref le_audio_profile_event_gatt_common_data_t for event data */
    le_audio_profile_event_gatt_notify_ind,                 /*!< \ref le_audio_profile_event_gatt_common_data_t for event data */
    le_audio_profile_event_char_read_rsp,                   /*!< \ref le_audio_profile_event_characteristic_read_data_t for event data */
    le_audio_profile_event_char_write_rsp,                  /*!< \ref le_audio_profile_event_char_write_rsp_data_t for event data */
    le_audio_profile_event_service_discovered,              /*!< \ref le_audio_profile_service_discovered_data_t for event data */
    le_audio_profile_event_connection_state_change,         /*!< \ref le_audio_profile_event_connection_state_change_data_t for event data */
    le_audio_profile_event_custom_data,                     /*!< \ref le_audio_profile_event_custom_data_t for event data */
    le_audio_profile_event_gatt_att_error_response_sent,
    le_audio_profile_event_gatt_att_error_response_receive,
    le_audio_profile_event_vcp_volume_state_change,
    le_audio_profile_event_invalid
} le_audio_profile_event_t;

/*! \brief The data sent with the le_audio_profile_event_gatt_* event. */
typedef struct
{
    bool            local_originated;   /*!< Indicates locally or remote generated */
    uint16          uuid;               /*!< UUID where GATT operation was performed */
    uint16          handle;             /*!< Connection handle */
    uint16          dummy;              /*!< Dummy variable to align 32 bit boundary */
    uint16          len;                /*!< Length of the data */
    /* Needs to be aligned 32-bit boundary before data member */
    uint8           data[1];            /*!< Event handler has to make copy of this if it needs data */
} le_audio_profile_event_gatt_common_data_t;

/*! \brief The data sent with the le_audio_profile_event_char_read_rsp event. */
typedef struct
{
    int             status;             /*!< Non zero is failure */
    int             type;               /*!< 0: cached value, 1: remote device */
    uint16          uuid;               /*!< UUID */
    uint16          handle;             /*!< Connection handle */
    uint16          dummy;              /*!< Dummy variable to align 32 bit boundary */
    uint16          len;                /*!< Length of data */
    /* Needs to be aligned 32-bit boundary before data member */
    uint8           data[1];            /*!< Characterstic value (Event handler has to make copy of this if it needs data) */
} le_audio_profile_event_char_read_rsp_data_t;

/*! \brief The data sent with the le_audio_profile_event_char_write_rsp event. */
typedef struct
{
    uint16          handle;             /*!< Connection handle */
    uint16          uuid;               /*!< UUID */
    int             status;             /*!< Non zero is failure */
} le_audio_profile_event_char_write_rsp_data_t;

/*! \brief The data sent with the le_audio_profile_event_service_discovered event. */
typedef struct
{
    uint16          handle;             /*!< Connection handle */
    int             status;             /*!< Non zero is failure */
} le_audio_profile_event_service_discovered_data_t;

/*! \brief The data sent with the le_audio_profile_event_connection_state_change event. */
typedef struct
{
    uint16          connection_handle;  /*!< Connection handle of LE*/
    uint16          uuid;               /*!< Valid only when role is service */
    int             status;             /*!< Status of connection */
} le_audio_profile_event_connection_state_change_data_t;

/*! \brief The data sent with the le_audio_profile_event_custom_data event. */
typedef struct
{
    int             status;             /*!< Status of connection */
    int             type;               /*!< Custom type */
    uint16          uuid;               /*!< Valid only when role is service */
    uint16          handle;             /*!< Connection handle */
    uint16          dummy;              /*!< Dummy variable to align 32 bit boundary */
    uint16          len;                /*!< Length of the data */
    /* Needs to be aligned 32-bit boundary before data member */
    uint8           data[1];            /*!< Custom Data */
} le_audio_profile_event_custom_data_t;

#define leAudioProfileEvent_CalcGattEventSize(char_len)     (offsetof(le_audio_profile_event_gatt_common_data_t, data) + (char_len))
#define leAudioProfileEvent_CalcCharReadEventSize(char_len) (offsetof(le_audio_profile_event_char_read_rsp_data_t, data) + (char_len))
#define leAudioProfileEvent_CalcCustomEventSize(data_len)   (offsetof(le_audio_profile_event_custom_data_t, data) + (data_len))

typedef struct
{
    uint16          handle;             /*!< Connection handle */
    uint8           opcode;
    uint16          att_handle;
    uint8           error_code;
} le_audio_profile_event_gatt_att_error_response_t;

#define le_audio_profile_event_gatt_att_error_response_sent_t le_audio_profile_event_gatt_att_error_response_t
#define le_audio_profile_event_gatt_att_error_response_receive_t le_audio_profile_event_gatt_att_error_response_t

typedef struct
{
    uint8          volume_setting;
    uint8          mute_state;
    event_origin_t origin;
} le_audio_profile_event_vcp_volume_state_change_t;

/*! @} */

#endif /* LE_AUDIO_PROFILE_CHANNEL_EVENT_SPEC_H_ */

